import {
  Body,
  Controller,
  DefaultValuePipe,
  Delete,
  Get,
  Inject,
  Param,
  ParseIntPipe,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { RoomService } from './room.service';
import { CreateRoomDto } from 'src/dto/CreateRoom.dto';
import { RequireLogin, RequirePermission } from 'src/decorator/index.decorator';
import { updateRoomDto } from 'src/dto/UpdateRoom.dto';

@Controller('room')
@RequireLogin()
export class RoomController {
  @Inject(RoomService)
  private readonly roomService: RoomService;

  @Get('list')
  async list(
    @Query('pageNum', new DefaultValuePipe(1), ParseIntPipe)
    pageNum: number,
    @Query('pageSize', new DefaultValuePipe(99999), ParseIntPipe)
    pageSize: number,
    @Query('name') name: string,
    @Query('capacity') capacity: number,
    @Query('equipment') equipment: string,
  ) {
    return await this.roomService.getRoomList(
      pageNum,
      pageSize,
      name,
      capacity,
      equipment,
    );
  }

  @Post('create')
  @RequirePermission('create_room')
  async createRoom(@Body() room: CreateRoomDto) {
    return await this.roomService.createRoom(room);
  }

  @Patch('update')
  @RequirePermission('update_room')
  async updateRoom(@Body() room: updateRoomDto) {
    return await this.roomService.updateRoom(room);
  }

  @Get(':id')
  async getRoomInfo(@Param('id', ParseIntPipe) id: number) {
    return await this.roomService.getRoomInfoById(id);
  }

  @Delete(':id')
  @RequirePermission('delete_room')
  async deleteRoom(@Param('id', ParseIntPipe) id: number) {
    return await this.roomService.deleteRoom(id);
  }
}
